package cn.element.io.nio.case1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ServerRunnableTarget implements Runnable {

    private final Socket socket;

    public ServerRunnableTarget(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));

            String l;
            if ((l = br.readLine()) != null) {
                System.out.println("服务端接收: " + l);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
